package cn.dengta.webapp.user.dto;

import cn.dengta.context.rpc.CachedConfig;
import cn.dengta.context.rpc.CachedConfigManager;
import cn.dengta.webapp.user.dto.common.BaseConfig;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class UserCommonConfig {

	private BaseConfig baseConfig;

	public static UserCommonConfig getDefault() {
		UserCommonConfig config = new UserCommonConfig();
		config.setBaseConfig(BaseConfig.getDefault());
		return config;
	}

	public static BaseConfig buildBaseConfig() {
		return cache().get().getBaseConfig() == null ? BaseConfig.getDefault() : cache().get().getBaseConfig();
	}

	public static CachedConfig<UserCommonConfig> cache() {
		return UserCommonConfig.InstanceHolder.instance;
	}

	private static final class InstanceHolder {

		static final CachedConfig<UserCommonConfig> instance = CachedConfigManager.create(UserCommonConfig.class, UserCommonConfig::getDefault);

	}

}
